package com.jinzhuo.rabbitmq_config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Mq_provider {
    public static final String EXCHANGE_NAME="exchange";
    public static final String QUEUE_NAME="queue";
    //1交换机
    @Bean("exchange1")
    public Exchange exchange(){
        return ExchangeBuilder.directExchange(EXCHANGE_NAME).durable(true).build();

    }

    //2队列
    @Bean("queue1")
    public Queue queue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    //3绑定交换机和队列
    @Bean
    public Binding binding(@Qualifier("queue1") Queue queue,@Qualifier("exchange1") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("queue1").noargs();
    }

}
